﻿using System;
using System.Linq;
using System.Web.Mvc;
using ControleRepresentante.Common;
using ControleRepresentante.Logic.Models;
using Telerik.Web.Mvc.UI.Fluent;

namespace WebSite.ViewModels.DetailsViewModels.DetailsGridViewModels
{
    public class ContatoDetailsGridViewModel : DetailsGridViewModel<Contato>
    {
        private readonly DetailsHolder m_DetailsHolder;

        public ContatoDetailsGridViewModel(HtmlHelper htmlHelper, DetailsHolder detailsHolder)
            : base(htmlHelper, "Contato", detailsHolder.Contatos)
        {
            m_DetailsHolder = detailsHolder;
        }

        protected override void Columns(GridColumnFactory<Contato> configurator)
        {
            configurator.Bound(contato => contato.Tipo).Template(x => x.Tipo.GetDescription());
            configurator.Bound(contato => contato.Valor);
            if (m_DetailsHolder.Contatos.Any(x => !String.IsNullOrWhiteSpace(x.Observacao)))
            {
                configurator.Bound(contato => contato.Observacao).HeaderTemplate("Observação");
            }
            configurator.Bound(contato => contato.Principal);
        }
    }
}